
#include "Localization_Env_Read.h"
#include <stdlib.h>

//constructor
Localization_Env_Read::Localization_Env_Read()
:
_grid_size_x(0),
_grid_size_y(0),
_square_size_x(0),
_square_size_y(0),
_size_dead_zone(0),
_size_path_width(0),
_angle_offset(0)
{
   UpdateAllEnvVars();
}

//destructor
Localization_Env_Read::~Localization_Env_Read()
{
   
}

//Calling this function will return the value last read by the update
//function
uint32_t Localization_Env_Read::GetXGridSize()
{
   return _grid_size_x;
}

//Calling this function will return the value last read by the update
//function
uint32_t Localization_Env_Read::GetYGridSize()
{
   return _grid_size_y;
}

//Calling this function will return the value last read by the update
//function
double Localization_Env_Read::GetXSquareSize()
{
   return _square_size_x;
}

//Calling this function will return the value last read by the update
//function
double Localization_Env_Read::GetYSquareSize()
{
   return _square_size_y;
}

//Calling this function will return the value last read by the update
//function
double Localization_Env_Read::GetDeadZoneSize()
{
   return _size_dead_zone;
}

//Calling this function will return the value last read by the update
//function
double Localization_Env_Read::GetPathWidthSize()
{
   return _size_path_width;
}

//Calling this function will return the value last read by the update
//function
double Localization_Env_Read::GetAngleOffset()
{
   return _angle_offset;
}


//calling this function will update all its internally stored
//variables with the current environment variable values in the 
//system
void Localization_Env_Read::UpdateAllEnvVars()
{
   char *var;
   double val = 0;

   var = getenv("LOC_GRID_SIZE_X");

   if (var != NULL)
   {
      val = atoi(var);

      if (val >= 0)
      {
         _grid_size_x = val;
      }
   }

   var = getenv("LOC_GRID_SIZE_Y");

   if (var != NULL)
   {
      val = atoi(var);

      if (val >= 0)
      {
         _grid_size_y = val;
      }
   }

   var = getenv("LOC_SQUARE_SIZE_X");

   if (var != NULL)
   {
      val = atof(var);

      if (val >= 0)
      {
         _square_size_x = val;
      }
   }

   var = getenv("LOC_SQUARE_SIZE_Y");

   if (var != NULL)
   {
      val = atof(var);

      if (val >= 0)
      {
         _square_size_y = val;
      }
   }

   var = getenv("LOC_SIZE_DEAD_ZONE");

   if (var != NULL)
   {
      val = atof(var);

      if (val >= 0)
      {
         _size_dead_zone = val;
      }
   }

   var = getenv("LOC_SIZE_PATH_WIDTH");

   if (var != NULL)
   {
      val = atof(var);

      if (val >= 0)
      {
         _size_path_width = val;
      }
   }

   var = getenv("LOC_ANGLE_OFFSET");

   if (var != NULL)
   {
      val = atof(var);

      if (val >= 0)
      {
         _angle_offset = val;
      }
   }


}


